home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Using a Pen to Draw Lines and Shapes / Drawing a Line with Line Caps / GDITEST26.dpr
Encoding:
Text File  |  2003-10-15  |  2.3 KB  |  90 lines

  1. program GDITEST27;
  2.  
  3. uses
  4.   Windows,
  5.   Messages,
  6.   SysUtils,
  7.   GDIPAPI,
  8.   GDIPOBJ;
  9.  
  10. Procedure OnPaint(DC: HDC);
  11. var
  12.   graphics : TGPGraphics;
  13.   pen: TGPPen;
  14. begin
  15.   graphics := TGPGraphics.Create(DC);
  16.   pen:= TGPPen.Create(MakeColor(255, 0, 0, 255), 8);
  17.   pen.SetStartCap(LineCapArrowAnchor);
  18.   pen.SetEndCap(LineCapRoundAnchor);
  19.   graphics.DrawLine(pen, 20, 175, 300, 175);
  20.   pen.Free;
  21.   graphics.Free;
  22. end;
  23.  
  24.  
  25. function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
  26. var
  27.   Handle: HDC;
  28.   ps: PAINTSTRUCT;
  29. begin
  30.   case message of
  31.     WM_PAINT:
  32.       begin
  33.         Handle := BeginPaint(Wnd, ps);
  34.         OnPaint(Handle);
  35.         EndPaint(Wnd, ps);
  36.         result := 0;
  37.       end;
  38.  
  39.     WM_DESTROY:
  40.       begin
  41.         PostQuitMessage(0);
  42.         result := 0;
  43.       end;
  44.  
  45.    else
  46.       result := DefWindowProc(Wnd, message, wParam, lParam);
  47.    end;
  48. end;
  49.  
  50. var
  51.   hWnd     : THandle;
  52.   Msg      : TMsg;
  53.   wndClass : TWndClass;
  54. begin
  55.    wndClass.style          := CS_HREDRAW or CS_VREDRAW;
  56.    wndClass.lpfnWndProc    := @WndProc;
  57.    wndClass.cbClsExtra     := 0;
  58.    wndClass.cbWndExtra     := 0;
  59.    wndClass.hInstance      := hInstance;
  60.    wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
  61.    wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
  62.    wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
  63.    wndClass.lpszMenuName   := nil;
  64.    wndClass.lpszClassName  := 'GettingStarted';
  65.  
  66.    RegisterClass(wndClass);
  67.  
  68.    hWnd := CreateWindow(
  69.       'GettingStarted',       // window class name
  70.       'Drawing a Line with Line Caps',      // window caption
  71.       WS_OVERLAPPEDWINDOW,    // window style
  72.       Integer(CW_USEDEFAULT), // initial x position
  73.       Integer(CW_USEDEFAULT), // initial y position
  74.       Integer(CW_USEDEFAULT), // initial x size
  75.       Integer(CW_USEDEFAULT), // initial y size
  76.       0,                      // parent window handle
  77.       0,                      // window menu handle
  78.       hInstance,              // program instance handle
  79.       nil);                   // creation parameters
  80.  
  81.    ShowWindow(hWnd, SW_SHOW);
  82.    UpdateWindow(hWnd);
  83.  
  84.    while(GetMessage(msg, 0, 0, 0)) do
  85.    begin
  86.       TranslateMessage(msg);
  87.       DispatchMessage(msg);
  88.    end;
  89. end.
  90.